import {
	Component
} from '@angular/core';

import {
	Geolocation
} from '@ionic-native/geolocation';
import {
	Device
} from '@ionic-native/device';
import {
	Camera,
	CameraOptions
} from '@ionic-native/camera';

import {
	NavController,
	Platform,
	ActionSheetController
} from 'ionic-angular';

@Component({
	selector: 'page-mine',
	templateUrl: 'mine.html'
})
export class MinePage {
	constructor(
		public navCtrl: NavController,
		public platform: Platform,
		public actionsheetCtrl: ActionSheetController,
		private geolocation: Geolocation,
		public device: Device,
		private camera: Camera
	) {}

	//弹出弹框
	openMenu() {
		let actionSheet = this.actionsheetCtrl.create({
			title: '更换头像',
			cssClass: 'action-sheets-basic-page',
			buttons: [{
				text: '从相册中获取',
				role: 'destructive',
				icon: !this.platform.is('ios') ? 'trash' : null,
				handler: () => {
					console.log('从相册中获取 clicked');
				}
			}, {
				text: '拍照',
				icon: !this.platform.is('ios') ? 'share' : null,
				handler: () => {
					console.log('拍照 clicked');
					//获取相册和摄像头
					const options: CameraOptions = {
						quality: 100,
						destinationType: this.camera.DestinationType.DATA_URL,//目标类型
						encodingType: this.camera.EncodingType.JPEG,
						mediaType: this.camera.MediaType.PICTURE
					}
				
					this.camera.getPicture(options).then((imageData) => {
						// imageData is either a base64 encoded string or a file URI
						// If it's base64:
						let base64Image = 'data:image/jpeg;base64,' + imageData;
					}, (err) => {
						// Handle error
					});
				}
			}, {
				text: '取消',
				role: 'cancel', // will always sort to be on the bottom
				icon: !this.platform.is('ios') ? 'close' : null,
				handler: () => {
					console.log('取消 clicked');
				}
			}]
		});
		actionSheet.present();
	}

	//获取地理位置
	getLocation() {
		this.geolocation.getCurrentPosition().then(pos => {
			console.log("lat:" + pos.coords.latitude + ",lon:" + pos.coords.longitude);
		});
	}

	//获取硬件的设备信息
	getDevice() {
		console.log(this.device);
	}

}